/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    gpio.h
  * @brief   This file contains all the function prototypes for
  *          the gpio.c file
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __BSP_GPIO_H__
#define __BSP_GPIO_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* USER CODE BEGIN Private defines */

/* led defines *******************************************************/

#define LED_ON          0
#define LED_OFF         1

#define RUN_LED_SET(sta)         bsp_led_set(&LED1, sta)
#define ALARM_LED_SET(sta)       bsp_led_set(&LED2, sta)

typedef struct{
    u8 sta;
    void (*setsta)(u8 sta);
}led_obj;
extern led_obj LED1;
extern led_obj LED2;
extern led_obj LED3;
extern led_obj LED4;
extern led_obj LED5;
extern led_obj LED6;

/* key defines *******************************************************/
/* 按键模式只用其中一种 */
#define KEY_USE_POLL            
//#define KEY_USE_INTERRUPT           

#define KEY_DEFAULT_VALUE           0XFFFF
#define KEY_PRESS_VALUE             0X0000

#define KEY_PRESS                   0XAA
#define KEY_UP                      0X55

#define KEY_PIN_READ(port, pin)         HAL_GPIO_ReadPin(port, pin)
#define KEY_OBJ_READ(obj)               KEY_PIN_READ(obj.obj->port, obj.obj->pin)

typedef u8 (*keycallback) (u8);

typedef struct
{
    u16 pin;
    GPIO_TypeDef *port;
    u16 old_sta;
    u16 new_sta;
    u8 keyvalue;
}_drv_key;

typedef struct {
    u8 id;
    _drv_key *obj;
    void(*open)(u8 key);
    void(*close)(u8 key);
    u8 (*get_keyvalue)(u8 key);
    u8 (*callback)(u8 keyvalue);
}key_obj;

/* USER CODE END Private defines */

void MX_GPIO_Init(void);
void bsp_led_set(led_obj *led, u8 sta);

/* USER CODE BEGIN Prototypes */
void key_scan_test_init(void);
void key_scan_test(void);

/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif
#endif /*__ GPIO_H__ */

